from flask_restful import Resource, Api
from flask import Blueprint, request
from libs.response import generate_response
from model.models import Commodity, db


homeapi_bp = Blueprint("homeapi", __name__)
api = Api(homeapi_bp)


class HomeApi(Resource):
    def get(self):
        tmp = []
        commodity = Commodity.query.all()
        print(commodity)
        for i in commodity:
            tmp.append(i.to_json())

        return generate_response(data=tmp, message="get commodity success", status_code=2000)



api.add_resource(HomeApi, "/homeapi", "/")
# api.add_resource(LoginApi, "/loginapi/<id>", endpoint='stuapiid')

